192B - Walking in the Rain - CodeForces Solution


brute force implementation *1100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
#define fre freopen("input.txt","r",stdin) , freopen("output.txt","w",stdout) ;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
const int N = 1e5 + 5;
using namespace std;


void solve() {
    int n;cin>>n;
    vector<int>vec(n);
    for (int i = n-1; i >= 0; --i) {
        cin>>vec[i];
    }
    int start=vec[0];
    int end = vec[n-1];
    int count=0;
    bool valid=true;
    while(vec[0]!=0){
        valid=true;
        for (int j = 0; j < n;) {
            if(vec[j]>0){
                vec[j]--;
                if(vec[j+1]!=0){j++;}
                else{
                    j+=2;
                }
            }else{
                valid=false;
                break;
            }
        }
        if(valid)count++;
    }
    cout<<min(count,min(start,end))<<"\n";

}

int main() {
    IO
    int t;
//  cin >> t;
    t = 1;
    while (t--) {
        solve();
    }
}

/*

 // you can use includes, for example:
#include <bits/stdc++.h>
using namespace std;
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;


bool arr[15];
bool isCool(int num){
    string s = to_string(num);
    // pali
    int size = s.size();
    for(int i =0 ; i <=size/2; i++){
        if(s[i]!=s[size-i-1]){
            return false;
        }
    }

    map<char,int>mp;
    for(int i =0 ; i < size; i++){
        if(mp[s[i]]!=0){
            return false;
        }else{
            mp[s[i]]++;
        }
    }
    return true;
}
int total=0;
int mx=-1;
int magic(int sum ,int numOfCoolOnesr ,vector<int> vec ){

    if(sum==total){
        return numOfCoolOnesr;
    }
    int cool =numOfCoolOnesr;
    for(int i = 0 ; i < vec.size() ; i++){
        if(!arr[0]){
            arr[0]=true;
            if(isCool(sum+vec[i])){
                cool++;
            }
            mx=max(mx,magic(sum+vec[i],cool,vec));
            arr[0]=false;
        }
    }

}


int solution(int X, vector<int> &B) {
    // Implement your solution here
    for(int i = 0 ; i < B.size() ; i++){
        total+= B[i];
    }
    magic(X,0,B);
    return mx;

}


  */


Comments

Submit
0 Comments
More Questions

1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy